//---------------------------------------------------------------------
//
// Author: jachymko
//
// Description: Class used by PingExecutor to collect statistics.
//
// Creation date: Dec 14, 2006
//
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Pscx.Commands.Net
{
    partial class PingExecutor
    {
        internal class StatisticCounter : IEnumerable<PingHostStatistics>
        {
            readonly Dictionary<IPHostEntry, PingHostStatistics> items = new Dictionary<IPHostEntry, PingHostStatistics>();

            public void Add(PingHostInfo result)
            {
                if (!items.ContainsKey(result.Host))
                    items[result.Host] = new PingHostStatistics(result.Host);

                items[result.Host].Replies.Add(result.Reply);
            }

            public PingHostStatistics this[IPHostEntry host] 
            {
                get
                {
                    return items[host];
                }
            }

            public IEnumerator<PingHostStatistics> GetEnumerator()
            {
                return items.Values.GetEnumerator();
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return items.Values.GetEnumerator();
            }
        }
    }
}
